package com.atom.process.cnmuseum.cj.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.atom.common.entity.HistoricTaskDO;
import com.atom.common.entity.RunningTaskDO;
import com.atom.common.remote.user.UserUtil;

@Service
public class TaskListService extends AbstractService {

	public List<RunningTaskDO> getRunningTaskList(UserUtil user) {

		try {
			List<RunningTaskDO> list = runningTaskHandler.getListByUser(user.getUserid());
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public List<RunningTaskDO> getRunningTaskList(UserUtil user, String titlename, int start, int count) {

		try {
			if(isEmpty(titlename)){
				List<RunningTaskDO> list = runningTaskHandler.getListByUserAndPage(user.getUserid(),start,count);
				return list;
			}else{
				List<RunningTaskDO> list = runningTaskHandler.getListByUserAndTitleAndPage(user.getUserid(),titlename,start,count);
				return list;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public int getRunningTaskCount(UserUtil user, String titlename) {

		try {
			if(isEmpty(titlename)){
				List<RunningTaskDO> list = runningTaskHandler.getListByUser(user.getUserid());
				return list.size();
			}else{
				List<RunningTaskDO> list = runningTaskHandler.getListByUserAndTitle(user.getUserid(),titlename);
				return list.size();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public List<RunningTaskDO> getRunningTaskList(UserUtil user, String titlename, String taskDefinitionKey, int start, int count) {

		try {
			if(isEmpty(titlename)){
				List<RunningTaskDO> list = runningTaskHandler.getListByUserAndPage(user.getUserid(),taskDefinitionKey,start,count);
				return list;
			}else{
				List<RunningTaskDO> list = runningTaskHandler.getListByUserAndTitleAndPage(user.getUserid(),titlename,taskDefinitionKey,start,count);
				return list;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public int getRunningTaskCount(UserUtil user, String titlename, String taskDefinitionKey) {

		try {
			if(isEmpty(titlename)){
				List<RunningTaskDO> list = runningTaskHandler.getListByUser(user.getUserid(), taskDefinitionKey);
				return list.size();
			}else{
				List<RunningTaskDO> list = runningTaskHandler.getListByUserAndTitle(user.getUserid(),titlename, taskDefinitionKey);
				return list.size();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	public List<HistoricTaskDO> getHistoricTaskList(UserUtil user) {

		try {
			List<HistoricTaskDO> list = historicTaskHandler.getListByUser(user.getUserid());
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public List<HistoricTaskDO> getHistoricTaskList(UserUtil user, String titlename, int start, int count) {

		try {
			if(isEmpty(titlename)){
				List<HistoricTaskDO> list = historicTaskHandler.getListByUserAndPage(user.getUserid(), start, count);
				return list;
			}else{
				List<HistoricTaskDO> list = historicTaskHandler.getListByUserAndTitleAndPage(user.getUserid(),titlename, start, count);
				return list;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public int getHistoricTaskCount(UserUtil user, String titlename) {

		try {
			if(isEmpty(titlename)){
				List<HistoricTaskDO> list = historicTaskHandler.getListByUser(user.getUserid());
				return list.size();
			}else{
				List<HistoricTaskDO> list = historicTaskHandler.getListByUserAndTitle(user.getUserid(),titlename);
				return list.size();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public List<RunningTaskDO> getRunningTaskListByTaskId(String taskid) {

		try {
			List<RunningTaskDO> list = runningTaskHandler.getListByTaskId(taskid);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	} 
	
	/**      
	 * isEmpty(是否为空判断) 
	 * @author wangli
	 * @param str
	 * @return          
	*/
	public static boolean isEmpty(String str){
		if(str == null || str.length() <= 0){
			return true;
		}
		return false;
	}
	
	/**      
	 * isNoEmpty(是否不为空判断) 
	 * @author wangli
	 * @param str
	 * @return          
	*/
	public static boolean isNoEmpty(String str){
		if(str == null || str.length() <= 0){
			return false;
		}
		return true;
	}

}
